import {proxyModule} from 'tscommon/ts/vm.ext';
import {ValidTools} from 'tscommon/ts/Valid.tools';
import {Lang} from 'tscommon/ts/lang.pro';

const ValidCfg = new ValidTools([
  {field:"username",desc:Lang.userName,valids:["required"]},
  {field:"pwd",desc:Lang.pwd,valids:["required"]}
]);

const {data,onCreate,onDestroy,onReady,onRefresh,onShow,events} = proxyModule({
  data(){
    return {
      username:'' as string,
      pwd:'' as string,
      valid:{}
    };
  },
  events:{
    async login(){
      const [flag,result]=await ValidCfg.valid({username:this.username,pwd:this.pwd});
      this.valid = result;
      if(!flag){
        return "验证未通过";
      }
      console.log('登录',this.username,this.pwd);
      return null;
    }
  }
});

export  {data,onCreate,onDestroy,onReady,onRefresh,onShow,events};